package br.com.toscano.gobra.domain;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity 
@Table(name="COMPOSICAO_BDI")

public class ComposicaoBDI  extends ObjetoAbstrato {

	private static final long serialVersionUID = 13454534543354504L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="CBDI_ID")
	private Long id;
	
	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "OBRA_ID")
	private Obra obra;
	
	@Column(name="CBDI_DESCRICAO", nullable=false, length=255)
	private String descricao;

	@Column(name = "CBDI_PERCENTUAL", nullable = false, precision = 19, scale = 2)
	private BigDecimal percentual;

	public ComposicaoBDI(){
		
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Obra getObra() {
		return obra;
	}

	public void setObra(Obra obra) {
		this.obra = obra;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public BigDecimal getPercentual() {
		return percentual;
	}

	public void setPercentual(BigDecimal percentual) {
		this.percentual = percentual;
	}

	public int hashCode() {
		StringBuffer sb = new StringBuffer();
		
		sb.append(this.getId());
		
		return sb.toString().hashCode();
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ComposicaoBDI other = (ComposicaoBDI) obj;
		 if ((id == null && other.id == null) || (id == 0 && other.id == 0)) {
				return obra != null && obra.equals(other.obra) && descricao != null && descricao.equals(other.descricao);
		}else if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}

}